from multiprocessing import Pool
import time
import os


def foo(n):
    time.sleep(1)
    print('In process', n, os.getpid())
    return n


def bar(*args):
    print('>>done: ', args, os.getpid())


pool = Pool(processes=9)
print('主进程: ', os.getpid())
for i in range(10):
    # pool.apply(func=foo, args=(i, ))
    pool.apply_async(func=foo, args=(i, ), callback=bar)
print('end')
pool.close()
pool.join()